<template>
	<view class="tabbar-list">
		<view class="tabbar-item" v-for="(item,index) in tabBarList" :key="index" @click="changeActive(item,index)">
			<image class="img" :src="activeIndex === index ? item.selectedIconPath : item.iconPath"></image>
			<view>{{ item.text }}</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	
	export default{
		computed: {
			...mapState('tabBarModule', ['activeIndex', 'tabBarList']),
		},
		methods: {
			...mapMutations('tabBarModule', ['setUserInfo', 'changeIndex']),
			// 修改点击的tabbar项
			changeActive(item, index) {
				this.changeIndex(index)
				uni.switchTab({
					url: item.pagePath
				})
			},
		},
		mounted() {
			// 模拟登录后获取的用户信息,'public'为公共模块,非'public'为我的模块
			this.setUserInfo('admin')
			// this.setUserInfo('mine') 用这个进行切换就能看到不同的底部tabbar
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar-list {
		display: flex;
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 100rpx;
		border: 1px solid #ccc;
		overflow: hidden;
 
		.tabbar-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
 
			.img {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}
</style>